/**
 * @description 证件信息展示卡片组件
 */
<template>
  <div class="list-card" :class="{ 'is-disabled': disabled }">
    <div class="card-left">
      <img 
        :src="cardImage" 
        :alt="title"
        @error="handleImageError" 
      />
    </div>
    <div class="card-right">
      <div class="card-right-title" :title="title">{{ title }}</div>
    </div>
  </div>
</template>

<script lang="ts" setup name="idInfo2">
import { ref, computed } from 'vue';
import defaultImage from './u279.png';

interface CardProps {
  /** 父组件传递的数据 */
  fatherMsg?: Record<string, any>;
  /** 是否禁用 */
  disabled?: boolean;
  /** 卡片标题 */
  title?: string;
  /** 自定义图片地址 */
  imageUrl?: string;
}

// 定义组件属性
const props = withDefaults(defineProps<CardProps>(), {
  fatherMsg: () => ({}),
  disabled: false,
  title: '产权证/国有土地使用证/集体土地使用证/购房合同',
  imageUrl: ''
});

// 图片地址处理
const cardImage = computed(() => props.imageUrl || defaultImage);

// 图片加载失败处理
const handleImageError = (e: Event) => {
  const imgElement = e.target as HTMLImageElement;
  imgElement.src = defaultImage;
};
</script>

<style lang="scss">
/* 全局样式 */
.main-page {
  background: #f7fafd;
}

.title-1 {
  &::before {
    position: absolute;
    content: '';
    left: 0;
    top: 42px;
    width: 9px;
    height: 60px;
    background: linear-gradient(90deg, rgba(97, 209, 211, 1) 35%, rgba(82, 181, 190, 1) 100%);
  }
}

.clearfix::after {
  content: '';
  display: table;
  clear: both;
}
</style>

<style lang="scss" scoped>
.list-card {
  display: flex;
  background-color: #dbdee2;
  border-radius: 3px;
  transition: opacity 0.3s ease;

  &.is-disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
}

.card-left {
  height: 70px;
  width: 70px;
  margin: 10px;
  border-radius: 50%;
  background-color: #e4e4e4;
  flex-shrink: 0;
  overflow: hidden;

  img {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    transition: transform 0.3s ease;

    &:hover {
      transform: scale(1.05);
    }
  }
}

.card-right {
  flex: 1;
  margin: 15px 0 10px;
  padding: 0 10px 8px;

  &-title {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}
</style>
